// pages/newsDec/newsDec.js
const util = require('../../utils/util.js')
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    newId: '', // 消息id
    userInfo: '',
    mohuanUser: '',
    id:'',
    newItem:'',
    title:'',
    content:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {    
    console.log('获取的参数')
    console.log(options)
    var that = this
    that.setData({
      userInfo: app.globalData.userInfo,
      mohuanUser: app.globalData.mohuanUser,
      newId: options.notificationId,
      id: options.index
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this
    // 获取消息列表缓存
    var newList = wx.getStorageSync('newList')
    var newIndex = that.data.id
    that.setData({
      newItem: newList[newIndex]
    })
    console.log(that.data.newItem)

    //已读消息
    var mohuanUser = app.globalData.mohuanUser
    var token = mohuanUser["X-AUTH-TOKEN"]
    var url = util.baseUrl
    wx.request({
      url: url + '/c2mwebservice/api/v2/notification/' + that.data.mohuanUser.memberId + '/' + that.data.newId + '/addReadRecord',
      method: 'post',
      header: {
        'content-type': 'application/json', // 默认值
        'X-AUTH-TOKEN': token,
      },      
      success: (res) => {
        console.log("消息已读接口成功")
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})